<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        li {
            list-style: none;
        }

        a {
            color: inherit;
            text-decoration: none;
        }

        .wrap {
            width: 600px;
            margin: 10px auto;
        }

        .wrap .navBar {
            display: flex;
        }

        .wrap .navBar li {
            flex: 1;
            text-align: center;
            line-height: 45px;
            border: 1px solid #333;
        }

        .wrap .navBar li+li {
            border-left: 0;
        }

        .active {
            background-color: #6ff;
            color: #fff;
        }

        .main>div {
            width: 600px;
            height: 300px;
            border: 1px solid #333;
            margin-top: 10px;
            text-align: center;
            line-height: 300px;
            display: none;
        }

        .wrap .main .show {
            display: block;
        }
    </style>
</head>

<body>
    <div class="wrap">
        <ul class="navBar">
            <li>tab_01</li>
            <li>tab_02</li>
            <li>tab_03</li>
            <li>tab_04</li>
            <li>tab_05</li>
            <li>tab_06</li>
        </ul>
        <div class="main">
            <div>1</div>
            <div>2</div>
            <div>3</div>
            <div>4</div>
            <div>5</div>
            <div>6</div>
        </div>

    </div>

</body>
<script>
    // 1。导航栏切换 默认第一个导航有活跃样式(特效),点击其他元素(把该元素变为活跃样式,清除上一个元素的活跃样式)
    // a. 谁是上一个 b. 我狠起来连自己都清除
    // 2.tab栏切换 点击导航 显示对应的盒子 => 下标对应
    var navBar = document.getElementsByClassName("navBar")[0];
    var liList = navBar.getElementsByTagName("li");
    var main = document.querySelectorAll(".main>div");
    console.log(main);


    // let在块级作用声明的变量 也是局部的
    //循环绑定事件
    for (let i = 0; i < liList.length; i++) { // i<6
        let li = liList[i];
        var re = null;
        liList[0].setAttribute("class", "active");
        main[0].setAttribute("class", "show");

        li.onclick = function () {
            //循环清除样式
            for (var j = 0; j < liList.length; j++) {
                liList[j].className = "";
                main[j].removeAttribute("class");
            }

            liList[i].setAttribute("class", "active");
            main[i].className = "show";


        }

    }
</script>

</html>